<?php
require_once '../init.php';

//单个验证
include_once PATH_CORE.'/validator/RequiredValidator.php';
$row['name']='';
$oRequiredValidator=new RequiredValidator();
var_dump($oRequiredValidator->validate('姓名',$row['name']));
echo '<br/>';

include_once PATH_CORE.'/validator/DateValidator.php';
$row['date']='2011-07-17 17:37';
$oDateValidator=new DateValidator();
var_dump($oDateValidator->validate('日期',$row['date']));
echo '<br/>';

include_once PATH_CORE.'/validator/LengthValidator.php';
$oLengthValidator=new LengthValidator();
$oLengthValidator->min=2;
$oLengthValidator->max=10;
$oLengthValidator->encoding='UTF-8';
var_dump($oLengthValidator->validate('姓名',$row['name']));
echo '<br/>';

include_once PATH_CORE.'/validator/IntValidator.php';
$row['age']=120;
$oIntValidator=new IntValidator();
$oIntValidator->min=1;
$oIntValidator->max=100;
var_dump($oIntValidator->validate('年龄',$row['age']));
echo '<br/>';

include_once PATH_CORE.'/validator/NumberValidator.php';
$row['money']=70.3;
$oNumberValidator=new NumberValidator();
$oNumberValidator->min=2;
$oNumberValidator->max=60.6;
var_dump($oNumberValidator->validate('金额',$row['money']));
echo '<br/>';

include_once PATH_CORE.'/validator/AmongValidator.php';
$row['gender']='ma';
$oAmongValidator=new AmongValidator();
$oAmongValidator->range=array('man','woman');
var_dump($oAmongValidator->validate('性别',$row['gender']));
echo '<br/>';

include_once PATH_CORE.'/validator/MatchValidator.php';
$oMatchValidator=new MatchValidator();
$oMatchValidator->pattern='/\w/';
var_dump($oMatchValidator->validate('年龄',$row['age']));
echo '<br/>';

//批量验证
include_once PATH_CORE.'/validator/Validator.php';
$oValidator=new Validator();
$oValidator->setRule('name',array('姓名','required'=>array('value'=>'ikylin','strict'=>true),'length'=>array('max'=>10)));
$oValidator->setRule('date',array('日期','date'));
$oValidator->setRule('age',array('年龄','int'=>array('min'=>1,'max'=>100)));
$oValidator->setRule('gender',array('性别','among'=>array('range'=>array('man','woman'),'not'=>true)));
$result=$oValidator->validate($row);
var_dump($result);
